create or replace package m4o_lexer as

  subtype token_t is pls_integer;
--------------------------------------------------------------------------------
  -- pseudo-tokens.
  -- EOF gets returned when everything is read.
  -- WS never gets returned. it is the token of set_whitespace().
  EOF constant token_t := -1;
  WS  constant token_t := 0;
--------------------------------------------------------------------------------
  -- reset tokens
  procedure begin_define_tokens;
--------------------------------------------------------------------------------
  procedure set_whitespace(i_pattern in varchar2);
--------------------------------------------------------------------------------
  procedure set_token(
    i_token   in token_t,
    i_pattern in varchar2);
--------------------------------------------------------------------------------
  -- configure lexer such that cur() returns the first token.
  procedure begin_reading(i_text in clob);
--------------------------------------------------------------------------------
  -- ensure that we're on EOF and stop the lexer
  procedure end_reading;
--------------------------------------------------------------------------------
  -- get current token
  function cur return token_t;
--------------------------------------------------------------------------------
  -- get current token string value
  function text return varchar2;
--------------------------------------------------------------------------------
  -- eat current token and move to the next one
  procedure eat;
--------------------------------------------------------------------------------
  -- get current token and eat it, if it is i_token. else raise error.
  procedure eat(i_token in token_t);
end;
/
